package com.miao.manage.web.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.miao.entity.*;
import com.miao.service.TbItemCatService;
import com.miao.service.TbItemParamItemService;
import com.miao.service.TbItemParamService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.Date;

/**
 * <p>
 * 商品规格和商品的关系表 前端控制器
 * </p>
 *
 * @author shuangshuang
 * @since 2018-09-07
 */
@Controller
@RequestMapping("/tbItemParamItem")
public class TbItemParamItemController {

    //日志
    private static final Logger LOGGER = LoggerFactory.getLogger(TbItemCatController.class);

    //商品规则参数
    @Autowired
    private TbItemParamItemService tbItemParamItemService;
    //商品类目表
    @Autowired
    private TbItemCatService tbItemCatService;


    /**
     * 根据商品ID查询规格参数数据
     * @param itemId
     * @return
     */
    @RequestMapping(value = "{itemId}",method = RequestMethod.GET)
    public ResponseEntity<TbItemParamItem> queryByitemId(@RequestParam("itemId") Long itemId){
       try{
           EntityWrapper<TbItemParamItem> wrapper = new EntityWrapper<>();
           wrapper.where("item_id={0}",itemId);
           TbItemParamItem tbItemParamItem = tbItemParamItemService.selectOne(wrapper);
           if(null==tbItemParamItem){
               return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
           }
           return ResponseEntity.ok(tbItemParamItem);
       }catch (Exception e){
           e.printStackTrace();
       }
       return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * 查询规格参数
     * @return
     */
    @RequestMapping("/queryItemCat")
    public ResponseEntity<TbItemCat> queryItemCat(@RequestParam("itemCatId") Long itemCatId){
        EntityWrapper<TbItemCat> wrapper = new EntityWrapper<>();
        wrapper.where("id={0}",itemCatId);
        TbItemCat tbItemCat = tbItemCatService.selectOne(wrapper);
        return ResponseEntity.ok(tbItemCat);
    }






}

